﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using points.AppInfo;
using points.Assist;
using System.Configuration;

namespace points
{
    public partial class Consumer : Helper
    {
        //public SqlDataSource DSMain { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack){
                CheckPageUsage(AppVars.customer_type["consumer"].Pk);

                //buildDataSource();
            }

            buildDataSource();
        }

        protected void buildDataSource()
        {
            int customerPk = (int)Session["CUSTOMER_PK"];

            //DSMain = new SqlDataSource();
            //DSMain.ConnectionString = (string)ConfigurationManager.ConnectionStrings["POINTS_PROD"].ToString();
            string selectStr = "SELECT ct.[add_dt] as Date, merchant.[name_first] as Name1, merchant.[name_last] as Name2, ct.[point_value] as Points, ct.[msg] as Info" +
                            " FROM [customer_transaction] ct" +
                            " INNER JOIN [customer] consumer" +
                            "     ON ct.fk_customer_id = consumer.pk" +
                            " INNER JOIN [customer] merchant" +
                            "     ON ct.fk_merchant_id = merchant.pk" +
                            " INNER JOIN [customer] employee" +
                            "     ON ct.fk_employee_id = employee.pk" +
                            " WHERE consumer.pk=" + 
                            customerPk.ToString() +
                            " ORDER BY merchant.pk, ct.add_dt"
            ;

            DSMain.SelectCommand = selectStr;
        }
    }
}